package es.decoroso.communicationAgent.bean;

import java.util.logging.Level;
import java.util.logging.Logger;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Encapsulates the information about a Rower
 *  
 * @author Jesús W. Jiménez
 *
 */
public class Rower {
	int number;
	int place;
	
	/**
	 * Constructor of the class
	 * 
	 * @param number Number of the rower
	 * @param place Place occupied
	 */
	public Rower(int number, int place) {
		this.number = number;
		this.place = place;
	}
	
	/**
	 * Constructor of the class
	 * 
	 * Creates a message through a json object
	 * 
	 * @param js JSONObject with the information of the class
	 */
	public Rower (JSONObject js) {
		try {
			this.number = js.getInt("number");
			this.place = js.getInt("place");
		} catch (JSONException e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * Return the actual rower parsed to json
	 * 
	 * @return JSONObject with the rower information
	 */
	public JSONObject toJSON() {
        JSONObject js = new JSONObject();
        try {
        	js.put("number", number);
        	js.put("place", place);
        } catch (JSONException ex) {
            Logger.getLogger(Rower.class.getName()).log(Level.SEVERE, null, ex);
        }
        return js;
    }
	public int getNumber() {
	    return this.number;
	}

	  public void setNumber(int number) {
	    this.number = number;
	  }
	
	  public int getPlace() {
	    return this.place;
	  }
	
	  public void setPlace(int place) {
	    this.place = place;
	  }
	
	  public String toString(){
	    return toJSON().toString();
	  }
}
